<template>
    <div>
        <h1>门号增加</h1>
        <table class="table table-bordered">
            <tr>
                <td>门号</td>
                <td>
                    <input type="text" v-model="s.name">
                </td>
            </tr>

            <tr>
                <td>类型</td>
                <td>
                    <select v-model="s.type">
                        <option value="">请选择</option>
                        <option value="情趣大床房">情趣大床房</option>
                        <option value="普通标间">普通标间</option>
                        <option value="秘密钟点房">秘密钟点房</option>
                    </select>
                </td>
            </tr>

            <tr>
                <td>人数</td>
                <td>
                    <input type="text" v-model="s.num">
                </td>
            </tr>

            <tr>
                <td>地址</td>
                <td>
                    <input type="text" v-model="s.addr">
                </td>
            </tr>

            <tr>
                <td></td>
                <td>
                    <input type="button" value="增加" @click="add">
                </td>
            </tr>
        </table>
    </div>
</template>

<script setup lang="ts">
import { reactive, toRefs, onMounted } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import axios from 'axios';

let router = useRouter();
let route = useRoute();
let data: any = reactive({
    s: {
        name: "",
        type: "",
        num: "",
        addr: "",
    },
});

let { s } = toRefs(data);

const add = () => {
    let obj = {
        name:s.value.name,
        type: s.value.type,
        num: s.value.num,
        addr: s.value.addr,
    }
    axios({
        method: "post",
        url: "/api/ShopNumber/ShopAdd",
        data: obj
    }).then((res) => {
        if (res.data.data == -1) {
            alert("门号名称不能重复");
            return;
        }
        else if (res.data.data == 1) {
            alert("添加成功");
            router.push("/list");
        } else {
            alert("添加失败");
            return;
        }
    })
}

</script>

<style scoped></style>